import QtQuick 1.1
import com.nokia.meego 1.1
import "pages"
import "Script.js" as Script
import "Calcul.js" as Script2
Page {
    id: page
    tools: commonTools

    property string title : "QFTPower"
    property string bannerText: ""

    function start(){
        busyindicator.opacity = 1;
        busyindicator.running = true;
    }
    function stop(){
        busyindicator.opacity = 0;
        busyindicator.running = false;
    }

    Image {
        id: pageHeader
        anchors {
            top: page.top
            left: page.left
            right: page.right
        }

        height: parent.width < parent.height ? 72 : 46
        width: parent.width
        source: "image://theme/meegotouch-view-header-fixed" + (theme.inverted ? "-inverted" : "")
        z: 1

        Label {
            id: header
            anchors {
                verticalCenter: parent.verticalCenter
                left: parent.left
                leftMargin: 16
            }
            platformStyle: LabelStyle {
                fontFamily: "Nokia Pure Text Light"
                fontPixelSize: 32
            }
            text: page.title
        }

        BusyIndicator {
            id: busyindicator
            x: 294
            y: 15
            width: 50
            height: 50
            anchors.top: parent.top
            opacity: 0;
            anchors.topMargin: 15
            anchors.bottom: parent.bottom
            anchors.bottomMargin: 15
            anchors.right: parent.right
            anchors.rightMargin: 21
            Behavior on opacity { NumberAnimation { duration: 600 }}
        }
    }

    Connections{
        target: ftpManager
        ignoreUnknownSignals: true
        onErreurLogin:{

        }
        onErreurHost:{
            console.debug("Erreur host non trouvé")
            bannerText = "Host incorrect"
            infoBanner.show();
        }
        onListingFinished:{
            appWindow.pageStack.push(Qt.resolvedUrl("pages/Browser.qml"));
        }

        onConnected:{
            console.debug("[QML] Connecter");
            Script2.directoryName[0] = line_host.text
            stop();
            ftpManager.listage();
        }
        onRemoveSuccesfull:{
            console.debug("REMOVE Succesfull")
        }
        onMkdirSuccesfull:{
            console.debug("MKDIR Succesfull")
            bannerText = "Succesfull";
            infoBanner.open();
        }
        onDownloadProgress:{
//            console.debug("[QML]Download Progress " + progress + "/" + total);
        }
    }
    Flickable {
        id: pageFlickableContent
        anchors {
            top: pageHeader.bottom
            bottom: page.bottom
            left: page.left
            right: page.right
            margins: 16
        }
        contentHeight: pageContent.height
        contentWidth: pageContent.width
        flickableDirection: Flickable.VerticalFlick

        Column {
            id: pageContent
            width: page.width - pageFlickableContent.anchors.margins * 2
            spacing: 16
        }

        Button {
            id: button_connect
            y: 315
            text: qsTr("Connect");
            anchors.left: parent.left
            anchors.leftMargin: 0
            anchors.right: parent.right
            anchors.rightMargin: 0
            height: 60
            onClicked: {
                ftpManager.setHost(line_host.text,21);
                ftpManager.setLogin(line_user.text,line_pass.text);
                start();
            }
        }

        TextField {
            id: line_user
            x: 78
            y: 106
            width: 250
            height: 50
            text: "yekmen"
        }

        TextField {
            id: line_pass
            x: 78
            y: 181
            width: 250
            height: 50
            text: "btr2002"
            echoMode: TextInput.Password
        }

        TextField {
            id: line_host
            x: 78
            y: 36
            width: 250
            height: 50
            text: "192.168.1.3"
        }

        Label {
            id: label_host
            x: 10
            y: 56
            width: 70
            height: 10
            text: "Host:"
            anchors.right: line_host.left
            anchors.rightMargin: 0
            anchors.verticalCenter: line_host.verticalCenter
            verticalAlignment: Text.AlignTop
            wrapMode: Text.NoWrap
            horizontalAlignment: Text.AlignLeft
            font.pointSize: 10
        }

        Label {
            id: label_user
            x: 10
            y: 131
            width: 70
            height: 10
            text: "User:"
            anchors.right: line_user.left
            anchors.rightMargin: 0
            anchors.verticalCenter: line_user.verticalCenter
        }

        Label {
            id: label_pass
            x: 10
            y: 219
            width: 70
            height: 10
            text: "Pass:"
            anchors.right: line_pass.left
            anchors.rightMargin: 0
            anchors.verticalCenter: line_pass.verticalCenter
        }

        Button {
            id: button_deconnect
            x: 35
            y: 397
            width: 248
            height: 40
            text: qsTr("Disconnect")
            anchors.horizontalCenter: parent.horizontalCenter
            onClicked: {
                ftpManager.deconnecter();
//                console.debug(Qt.formatDateTime(new Date(), "hhmmss"));
            }
        }
    }
    ScrollDecorator {
        flickableItem: pageFlickableContent
    }
}
